        TITL DAI FIRMWARE 2E316-2E406  V1.1
        ORG   :E316
*
*
*
*******************
* SET CURSOR MODE *
*******************
*
* The format of cursor info is 1 byte cursor type
* and 1 byte of information.
* If the type = 0, the cursor flashes in colour.
* The info is a mask which is exored with the
* colour byte for that character to flash it.
* If the type = 1, the cursor alternates between
* the actual character and the one in the info.
*
* If flash entry is never called, cursor will be
* steady in the alternate colour (type 0) or per-
* manently the alternate character (type 1).
*
* Entry: HL points to new cursor info.
* Exit:  All registers preserved.
*
SCURM   PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        LDA   :009D     Get current screen mode
        RAR             Char mode ?
        CC    :E36B     Then delete current cursor
        MOV   A,M       Get new cursor type
        STA   :0074     Store it in pointer
        INX   H
        MOV   A,M       Get new cursor info
        STA   :0075     Store it in pointer
 REM
* Entry from CURSET:
 REM
SCM10   CC    :E344     Flash cursor once if in
 REM char mode
        JMP   :E138     Popall, ret
*
**************
* SET CURSOR *
**************
*
* Sets some cursor on the screen. Does not delete
* a previous cursor. The screen must already be
* in a character mode.
* Gets the contents of the cursor position address
* and stores it in the pointers.
*
* Entry: HL: Address new cursor position.
* Exit:  All registers preserved.
*
CURSET  PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        PUSH  H
        MOV   D,M       Get contents addr pointed at
 REM by new cursor
        DCX   H
        DCX   H
        DCX   H
        MOV   E,M       Get colour byte of this addr
        POP   H
        CALL  :D68D     Store contents and colour
 REM byte in cursor pointers
        NOP
        NOP
        STC             CY=1
        JMP   :E32A     Flash cursor, popall, ret
*
****************
* FLASH CURSOR *
****************
*
* Flashes the cursor once if in char mode,
* otherwise does nothing.
*
* Entry: None.
* Exit:  All registers preserved.
*
*SCURI
CURFL   PUSH  PSW
        PUSH  H
        LHLD  :0072     Get cursor pos addr
        MOV   A,H
        ORA   L         Check if addr is 0000
        JZ    :E35D     Abort if no cursor
        LDA   :0074     Get cursor type
        ORA   A         Check type
        LDA   :0075     Get cursor info
        JNZ   :E360     Jump if char type
 REM
* If 'colour' type:
 REM
        DCX   H         )
        DCX   H         ) Get addr colour byte
        DCX   H         )
        XRA   M         Exor mask with colour byte
CFL05   MOV   M,A       And reload colour byte
CFL10   POP   H
        POP   PSW
        RET
 REM
* If 'char' type:
 REM
CFL20   CMP   M         Check contents screen loc
CFL30   MOV   M,A       Move cursor info in loc
        JNZ   :E35D     Abort if contents screen
 REM loc is changed now
        LDA   :0077     Else: get contents scrn loc
        JMP   :E35C     Store it in this loc
*
*****************
* DELETE CURSOR *
*****************
*
* Deletes the current cursor. Loads the address
* pointed at by the cursor with the data stored
* in RAM (0076/77).
* Routine valid for character modes only.
*
* Entry: None.
* Exit:  All registers preserved.
*
CURDEL  PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        LHLD  :0076     Get contents cursor loc
        XCHG            in DE
        LHLD  :0072     Get cursor pos addr
        PUSH  H         Save it on stack
        LXI   H,:0000
        SHLD  :0072     Move cursor to addr 0000
        POP   H         Restore cursor pos addr
        MOV   A,H
        ORA   L         Check if addr is 0000
        JZ    :E388     Abort if no cursor
        MOV   M,D       Load data into screen loc
 REM pointed at by cursor
        DCX   H
        DCX   H
        DCX   H
        MOV   M,E       Load colourbyte into loc
 REM pointed at
CDL10   JMP   :E138     Popall, ret
*
***************************
* GET CHARACTER FROM LINE *
***************************
*
* Returns a character from some position on
* the current line.
*
* Entry: C: Line position of required character.
*           (max. legal value = 219).
* Exit:  A: Required character (car.ret if at
*           or past cursor).
*        BCDEHLF preserved.
*
SFETC   PUSH  B
        PUSH  D
        PUSH  H
        PUSH  PSW
        LXI   H,:0086   Total nr. of bytes/line
        LDA   :007B     Get number extended lines
        CALL  :EB46     Calc total nr of bytes
 REM (HL=A*HL)
        XCHG            in DE
        LHLD  :0078     Get addr line mode byte
 REM current line
        DAD   D         Calc start of line on screen
        LXI   D,:FFEA
        DAD   D         End indent area
        XCHG            in DE
        MVI   A,:F9     1st bytes on line not
 REM useable
        ADD   C         Add pos of required char on
 REM line
        PUSH  PSW
        MVI   B,:00
        JNC   :E3B2     Jump if in 1st 7 positions
        DCR   B
SFC10   SUI   :35       60 useable positions/line
        INR   B         Count nr of extended lines
        JNC   :E3AC     Jump if not on this line
SFC20   MOV   A,B       Nr of extensions in A
        LXI   H,:FFE4   Nr of not used bytes/line
        CALL  :EB46     ) Add-ons for line ends
        DAD   D         )
        POP   PSW       Restore pos of char on line
        MOV   E,A       into E
        CMC
        SBB   A
        MOV   D,A       D=char.count - nr of idents
        XCHG
        DAD   H         Pos *2 due to colour bytes
        XCHG
        CALL  :E6F2     Calc pos of reqd char
        XCHG            Addr in DE
        LHLD  :0072     Get cursor pos addr
        CALL  :E6FB     Compare it with addr of char
        MVI   A,:0D     Car.ret in A
        JNC   :E3D2     If on or after cursor
        LDAX  D         Get character from line
SFC30   MOV   H,A       Save it temporarily
        POP   PSW       Restore flags
        MOV   A,H       Get character in A
        POP   H
        POP   D
        POP   B
        RET
*
***************
* CHANGE MODE *
***************
*
* Change the mode of the screen.
*
* Entry: A: Code new mode.
* Exit:  ABCDEHL preserved.
*        CY=0: OK.
*        CY=1: Insufficient room for mode.
*
SSETM   STC             CY=1
        PUSH  PSW
        PUSH  B
        PUSH  D
        PUSH  H
        CPI   :FF       Mode 0 ?
        CZ    :E407     Then set up mode 0 screen
        CNZ   :E43E     Else: Set up screen for
 REM other modes
        JC    :E404     Jump if no room available
        LHLD  :008E     Get end of screen
        PUSH  D
        LXI   D,:0010   Nr of bytes in trailer
        DAD   D         Get 1st addr trailer area
        POP   D         Get addr 1st colour
        MVI   B,:0F     Depth of blank
        CALL  :E5FC     Init trailer area
        LHLD  :0084     Get 1st free byte
        ORA   A         Set flags on scrn mode byte
        CALL  :E5A6     Perform mem. management
        STA   :009D     Store current screen mode
        JMP   :E12E     Popall (CY=0), ret
 REM
* If error:
 REM
STM10   JMP   :E138     Popall (CY=1), ret
*
*
*
        UNL
SCURI   EQU CURFL
        LST
        END
